package com.gaoyi.crm.app;

import android.app.Application;
import android.content.Intent;

import com.gaoyi.crm.activity.LoginActivity;
import com.gaoyi.crm.db.CrmDatabase;
import com.gaoyi.crm.util.AppUtil;
import com.gaoyi.crm.util.CrashHandler;
import com.gs.zxinglibrary.zxing.activity.ZXingLibrary;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

public class MyApplication extends Application {

    private MyContainer mContainer;

    public MyContainer getContainer() {
        return mContainer;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        AppUtil.initContext(getApplicationContext());
        ZXingLibrary.initDisplayOpinion(this);
        CrmDatabase.getDatabase();
        mContainer = new MyContainer();
        // 捕获全局异常
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init();
    }

    public static void startLogin() {
        Intent intent = new Intent(AppUtil.getContext(), LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        AppUtil.getContext().startActivity(intent);
    }

    static {
        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context, layout) -> new ClassicsHeader(context));
        SmartRefreshLayout.setDefaultRefreshFooterCreator((context, layout) -> new ClassicsFooter(context));
    }
}
